package com.aidong.myprofile.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.aidong.myprofile.biz.MyCharmPartBiz;

/**
 * 魅力部位action
 * @author user
 *
 */
@ParentPackage("json")
@Namespace("/")
public class MyCharmPartAction {

	private MyCharmPartBiz charmPartBiz;

	@Autowired
	public void setCharmPartBiz(MyCharmPartBiz charmPartBiz) {
		this.charmPartBiz = charmPartBiz;
	}
	
	private Map<String, Object> map;

	@JSON
	public Map<String, Object> getMap() {
		return map;
	}
	
	private int idongId;

	public void setIdongId(int idongId) {
		this.idongId = idongId;
	}
	
	private String partName;
	
	public void setPartName(String partName) {
		this.partName = partName;
	}

	/**
	 * 我的魅力部位修改
	 * @return
	 */
	@Action(value="editmycharmpart",results={@Result(name="succ",type="json",params={"root","map"})})
	public String editMyCharmPart(){
		map = new HashMap<String, Object>();
		try {
			if(idongId > 0 && (!"".equals(partName) && partName != null)){
				List<Map<String, Object>> list = null;
				String arrPart[] = partName.split(",");
				if(arrPart.length > 0){
					list = new ArrayList<Map<String, Object>>();
					for (int i = 0; i < arrPart.length; i++) {
						Map<String, Object> paraMap = new HashMap<String, Object>();
			
						
						paraMap.put("idongId", idongId);
						paraMap.put("partName", arrPart[i]);
						list.add(paraMap);
					}
				}
				
				charmPartBiz.editMyCharmPart(idongId, list);
				map.put("code", 1);
				map.put("result", "修改成功");
				return "succ";
			}else{
				map.put("code", 0);
				map.put("msg", "参数缺失");
				return "succ";
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 0);
			map.put("msg", "系统异常");
			return "succ";
		}
	}
}
